<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            width: 500px;
            height: 450px;
            border: 1px solid #000;
            box-sizing: border-box;
            margin: 100px auto;
        }

        .top {
            width: 100%;
            height: 50px;
            line-height: 50px;
            list-style: none;
            display: flex;
            justify-content: space-between;
            text-align: center;
        }

        ul>li {
            width: 100px;
            height: 50px;
            border-right: 1px solid #ccc;
            box-sizing: border-box;
            background-color: skyblue;
        }

        .bottom {
            width: 100%;
            height: 400px;
        }

        .bottom .content {
            width: 100%;
            height: 100%;
            display: none;
        }

        .content:nth-child(1) {
            background-color: salmon;
            display: block;
        }

        .content:nth-child(2) {
            background-color: palegreen;
        }

        .content:nth-child(3) {
            background-color: pink;
        }

        .content:nth-child(4) {
            background-color: seagreen;
        }

        .content:nth-child(5) {
            background-color: purple;
        }

        .current {
            background-color: red;
        }
    </style>
</head>

<body>
    <div class="box">
        <ul class="top">
            <li class="current">新闻</li>
            <li>视频</li>
            <li>音乐</li>
            <li>军事</li>
            <li>财经</li>
        </ul>
        <div class="bottom">
            <div class="content">新闻的内容</div>
            <div class="content">视频的内容</div>
            <div class="content">音乐的内容</div>
            <div class="content">军事的内容</div>
            <div class="content">财经的内容</div>
        </div>
    </div>
    <script>
        class Tab {
            constructor() {
                this.lis = document.querySelectorAll('li');
                this.content = document.querySelectorAll('.content');
                this.previousIndex = 0;
                this.len = this.lis.length;
            }
            addClickEvent() {
                for (let i = 0; i < this.len; i++) {
                    let li = this.lis[i];
                    li.addEventListener(
                        'click',
                        () => {
                            this._clearStyle(i);
                        },
                        false
                    );
                }
            }
            _clearStyle(i) {
                let previousLi = this.lis[this.previousIndex];
                previousLi.className = '';
                this.content[this.previousIndex].style.display = 'none';
                this.lis[i].className = 'current';
                this.content[i].style.display = 'block';
                this.previousIndex = i;
            }
        }
        let s = new Tab();
        s.addClickEvent();
    </script>
</body>

</html>